/*

* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     Smart-Shop开源商城系统/ Java商城-首选电商平台系统 请务必保留此注释头信息
* |     开源地址: https://gitee.com/ningbo-qishan/gruul-mall
* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     可正常分享和学习源码,未经授权 不可商用！
* |     商业版中台购买/开源版商业授权 联系技术客服
* |     官网:  https://www.73app.cn/
* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     Copyright (c) 2016-2999 宁波启山智软科技有限公司
* |     版权所有 ,侵权必究！
* ------------------------------------------------------------------------

*/
package com.medusa.gruul.integral.web.controller.manager;


import com.medusa.gruul.common.core.annotation.EscapeLogin;
import com.medusa.gruul.common.core.util.Result;
import com.medusa.gruul.common.data.tenant.ShopContextHolder;
import com.medusa.gruul.integral.service.IIntegralRuleService;
import com.medusa.gruul.integral.service.IStepNumberService;
import com.medusa.gruul.integral.web.model.dto.manager.IntegralRuleDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 积分规则表 前端控制器
 * </p>
 *
 * @author xiaoq
 * @since 2019-11-19
 */
@RestController
@RequestMapping("/rule")
@Api(tags = "积分规则接口")
public class IntegralRuleController {
    @Autowired
    private IIntegralRuleService integralRuleService;

    /**
     * 获取积分商城规则
     *
     * @return 积分商城规则
     */
    @ApiOperation(value = "获取积分规则")
    @EscapeLogin
    @GetMapping("/get")
    public Result<List<IntegralRuleDto>> getIntegralRule() {
        String shopId = ShopContextHolder.getShopId();
        List<IntegralRuleDto> integralShopRule = integralRuleService.getIntegralShopRule(shopId);
        return Result.ok(integralShopRule);
    }


    /**
     * 修改积分商城规则
     *
     * @param integralRuleDto 积分商城规则
     * @return
     */
    @ApiOperation(value = "积分规则修改")
    @PutMapping("/update")
    public Result updateIntegralRule(@RequestBody List<IntegralRuleDto> integralRuleDto) {
        integralRuleService.updateIntegralRule(integralRuleDto);
        return Result.ok();
    }

    /**
     * 无用
     *
     * @param integralRuleDto
     * @return
     */
    @ApiOperation(value = "默认积分规则插入 --- 未对接")
    @PostMapping("saveDefault")
    public Result saveIntegralRule(@RequestBody List<IntegralRuleDto> integralRuleDto) {
        integralRuleService.saveIntegralRule(integralRuleDto);
        return Result.ok();
    }


}
